<template>
	<view>
		<cu-custom bgColor="bg-blue" :isBack="true">
			<block slot="content">{{school_name}}</block>
		</cu-custom>
		<view class="selfinfo">
			<view class="nameinfos flex">
				<!-- <image :src="logo" style="width: 80rpx; height: 80rpx; margin-right: 10rpx;" mode="aspectFill" ></image> -->
				<view>{{school_name}}</view>
			</view>
		</view>
		<view class="selfinfo">
			<view class="nameinfo">班级：{{class_name}}</view>
		</view>
		<view class="persomfir solid-bottom">
			<view>个人资料</view>
		</view>
		<view class="personProfile" style="background-color: #FFFFFF;">
			<view class="profileList flex">
				<view>姓名</view>
				<input class="input-box" placeholder="请输入真实姓名" v-model="real_name"/>
			</view>
			<view class="profileList flex">
				<view>手机号</view>
				<input class="input-box" placeholder="请输入电话号码" v-model="phone"/>
			</view>
			
		</view>
		<view class="buttomBut">
			<button @tap="request" style="width: 335rpx; height: 80rpx; line-height: 80rpx; background-color: #3b73f6; border-radius: 50rpx;">
				<text style="color: #ffffff; font-size: 30rpx;">加入</text>
			</button>
		</view>
	</view>
</template>

<script>
	const {appLogin,httpGet,httpPost,msg,timeToStr,ZC} = require("@/utils/common.js")
	export default {
		data() {
			return {
				join_token:'',
				real_name:'',
				phone:'',
				student_join_token:'',
				school_name:'',
				class_name:'',
				logo:''
			}
		},
		onLoad(option) {
			// option.join_token = '1639814536262';
			if(option.join_token){
				ZC('join_token',option.join_token,-1)
			}
			appLogin((user_info)=>{
				console.log(user_info)
				this.join_token = option.join_token
				if(!this.join_token)this.join_token = ZC('join_token')
				this.getschool()
			})
		},
		methods: {
			request(){
				if(!this.real_name){
					uni.showToast({
						icon:'none',
						title:'请输入真实姓名',
						duration: 2000
					});
					return;
				}
				if(!this.phone){
					uni.showToast({
						icon:'none',
						title:'请输入电话号码',
						duration:2000
					});
					return;
				}
				httpPost({
					url:'/api/student/student_join',
					data:{
						join_token:this.join_token,
						real_name:this.real_name,
						phone:this.phone,
						logo:this.logo
					}
				}).then(res=>{
					msg('加入成功',()=>{
						uni.navigateTo({
							url:"../business"
						})
					})
				}).catch((res)=>{
					msg(res.msg,'none')
				})
			},
			getschool(){
				httpGet({
					url:'/api/school/infoByToken',
					data:{
						// student_join_token:1636699833143,
						student_join_token:this.join_token
					}
				}).then((res)=>{
					console.log(res)
					this.student_join_token = res.result.student_join_token
					this.school_name = res.result.schoole_info.school_name
					this.class_name = res.result.class_info.class_name
					this.logo = res.result.schoole_info.logo
				})
			}
		}
	}
</script>

<style>
	.persomfir{
		padding: 30rpx 0rpx 30rpx 35rpx;
		width: 100%;
	}
	.profileList{
		width: 100%;
		height: 110rpx;
		text-align: left;
		line-height:110rpx;
		/* position: relative; */
		border-bottom: solid 1px #E7EBED;
		color: #666666;
		padding-left: 35rpx;
	}
	.input-box{
		position: fixed;
		right: 35rpx;
		color: #333333;
		font-size: 30rpx;
		text-align: right;
		line-height: 110rpx;
		height: 110rpx;
		/* flex: 1; */
		width: 100%;
		justify-content: center;
		align-items:center;
	}
	.buttomBut{
		height:100rpx;
		line-height:100rpx;
		width:100%;
		position:fixed;
		bottom:0;
		padding-top: 10rpx;
		/* display: flex; */
		background-color: #FFFFFF;
		justify-content: center;
		/* align-items:center; */
	}
	.nameinfo{
		text-align: center;
		font-size: 30rpx;
	}
	.nameinfos{
		/* align-items: center; */
		justify-content: center;
		font-size: 30rpx;
		margin-top: 20rpx;
	}
	.selfinfo{
		width: 100%;
		height: 80rpx;
		/* background-color: white; */
		line-height: 80rpx;
		/* border-bottom: solid 1px #E7EBED; */
	}

</style>
